/****************************************************************************
 * javascript for upload file by flash
 *
 * version : v0.1
 *
 * base on : jquery 1.10.2
 *           bootstrap v3.0
 *           swfupload v2.2
 ****************************************************************************/


var Chujue_Upload = function() {

    this.settings = {
        flash_url : "/static/swfupload/swfupload.swf",
        upload_url : "",
        
        button_placeholder_id : "spanButtonPlaceHolder",
        button_width: 84,
        button_height: 34,
        button_image_url: "",
        // button_text: '<span class="theFont">上传资源</span>',
        // button_text_style: ".theFont { font-size:15; }",
        button_text_left_padding: 0,
        button_text_top_padding: 3,
        
        file_size_limit : "600 MB",
        file_types_description : "All Files",
        file_upload_limit : 100,
        file_queue_limit : 0,
        custom_settings : {
            progressTarget : "fsUploadProgress",
            cancelButtonId : "btnCancel",
        },
        debug : false,
        
        // The event handler functions are defined in handlers.js
        file_queued_handler : fileQueued,
        file_queue_error_handler : fileQueueError,
        file_dialog_complete_handler : fileDialogComplete,
        upload_start_handler : uploadStart,
        upload_progress_handler : uploadProgress,
        upload_error_handler : uploadError,
        upload_success_handler : uploadSuccess,
        upload_complete_handler : uploadComplete,
        queue_complete_handler : queueComplete	// Queue plugin event
    };

    this.swfu;

    /* change SWFUpload control properties */
    this.set_button = function(btn_id, btn_img) {
        // this.settings["button_text"] = '<span class="theFont">' + btn_txt + '</span>';
        this.settings["button_image_url"] = btn_img;
        
        this.settings["button_placeholder_id"] = btn_id;
        // this.settings["button_image_url"] = btn_img;
    };

    this.set_uploadurl = function(upload_url) {
        // this.settings["flash_url"] = flash_url;
        this.settings["upload_url"] = upload_url;
    };

    this.set_filelimit = function(size, des) {
        this.settings["file_size_limit"] = size;
        this.settings["file_types_description"] = des;
    };

    this.set_custom_settings = function(progress_id) {
        this.settings["custom_settings"]["progressTarget"] = progress_id;
    }

    this.set_debug = function(is_debug) {
        this.settings["debug"] = is_debug;
    };

    /* functions about Chujue_Upload */
    this.init = function(btn_id, btn_img, progress_id, upload_url) {
        this.set_button(btn_id, btn_img);
        this.set_custom_settings(progress_id);
        this.set_uploadurl(upload_url);

        this.reload();
    };

    this.reload = function() {
        this.swfu = new SWFUpload(this.settings);
    };
};

/* @swfuname: 定位是第几个上传按钮传的
 * @file    : 上传文件的信息， file.name 就是已上传文件的文件名
 * @serverData    : 服务端返回的数据

function do_after_upload(swfuname, file, serverData){
    // do somethings after upload one file
}
*/
